home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / thenet / x1j4_src / pk96.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-02  |  13.9 KB  |  504 lines

  1. /*****************************************************************************/
  2. /*                                              */
  3. /*                                         */
  4. /*    *****              *****                      */
  5. /*     *****            *****                         */
  6. /*       *****          *****                         */
  7. /*         *****        *****                         */
  8. /*  ***************      ***************                     */
  9. /*  *****************    *****************                     */
  10. /*  ***************      ***************                     */
  11. /*         *****        *****       TheNet                    */
  12. /*       *****          *****       Portable. Compatible.         */
  13. /*     *****            *****       Public Domain             */
  14. /*    *****              *****    G8KBB                  */
  15. /*                                         */
  16. /* This software is public domain ONLY for non commercial use                */
  17. /*                                                                           */
  18. /*                                         */
  19. /*****************************************************************************/
  20.  
  21. /* 
  22.  * released as TheNet X-1J September 1993
  23.  *
  24.  * Modified for PK-96
  25.  */
  26.  
  27. #ifdef BANKED
  28. #define EXTERN
  29. #define VARIABLES
  30. #include "all.h"
  31. #include "tntyp.h"
  32. #include "tnl3v.h"
  33. #include "tnl4v.h"
  34. #include "miscv.h"
  35. #include "tnl7av.h"
  36. #ifdef IPROUTE
  37. #include "ip.h"
  38. #include "ipv.h"
  39. #endif
  40.  
  41. char    nulide[] =                /* leerer Ident             */
  42.                    {' ',' ',' ',' ',' ',' '};
  43.  
  44. char    beades[] = { 'I','D',' ',' ',' ',' ','\140' }; /* Call fuer Bake     */
  45. char    cqdest[] = { 'C','Q',' ',' ',' ',' ','\140' }; /* Call fuer CQ-Ruf   */
  46. char    cqdil[]  = "";                    /* Digiliste fuer CQ-Ruf */
  47. char    L4audit[] = "L4    `";
  48. char    L2audit[] = "L2    `";
  49.  
  50. #ifdef MANAGED
  51. char AudCon[] = "C ";
  52. char AudConAcc[] = "CA";
  53. char AudDisc[] = "D ";
  54. char AudDiscAcc[] = "DA";
  55. #endif
  56.  
  57. #ifdef PORTABLE
  58.  
  59. /* ***********************************************************************
  60.  * The timer() routine is called every 10 milliseconds.
  61.  * The portable version does NOT support the ancilliary
  62.  * functions of l1 stats and cwid
  63.  */
  64.  
  65. VOID timer()
  66. {
  67.     ++tic10;
  68. }
  69.  
  70. /* ***********************************************************************
  71.  * The stop() routine is used to halt the system upon
  72.  * closedown. WARNING - the portable version does not
  73.  * correctly initialise the SIO - so it may stop with
  74.  * the ptt enabled !!!!!! ( it's really only there for
  75.  * test purposes. )
  76.  */
  77.  
  78. VOID stop()
  79. {
  80.     DIinc();
  81. loop:    kick_wdog();
  82.     goto loop;
  83. }
  84.  
  85. #else
  86. #asm
  87.     .64180
  88. SIADAT    equ    07fh
  89. SIACTL    equ    07eh
  90. SIBDAT    equ    07dh
  91. SIBCTL    equ     07ch
  92. PTT    equ    0b0h
  93. MODEM_SEL equ    0b6h
  94.  
  95. ;  ***********************************************************************
  96. ;  The stop() routine is used to halt the system upon
  97. ;  closedown. 
  98.     extrn    SIAIW5    ; , SIBIW5
  99.     extrn    kick_wdog_
  100.  
  101.     public    stop_
  102. stop_:
  103.     di
  104.     ld    A,5
  105.     out    (SIACTL),A
  106.     ld    A,(SIAIW5)    ; turn off modem tone
  107.     out    (SIACTL),A
  108.     xor    A        ; switch off PTT
  109.     out0    (PTT),A
  110. ;    ld    A,5
  111. ;    out    (SIBCTL),A
  112. ;    ld    A,(SIBIW5)
  113. ;    out    (SIBCTL),A
  114. stoploop:
  115.     call    kick_wdog_
  116.     jr    stoploop
  117.  
  118. ; ***********************************************************************
  119. ; The timer() routine is called every 10 milliseconds.
  120. ; The non portable version supports the ancilliary
  121. ; functions of l1 stats and cwid
  122. ;
  123.  
  124.     public timer_
  125.     extrn tic10_, SIAWR5, SIARR0, txon_, dcdon_, SIAIW5
  126.     extrn cwtimr_
  127.  
  128. timer_:    
  129.     ld    hl,(tic10_)    ; bump the 10 millisecond counter
  130.     inc    hl
  131.     ld    (tic10_), hl
  132. #endasm
  133. #ifdef STATSCMD
  134. #asm
  135.     ld    a,(SIAWR5)    ; test for RTS on HDLC port, ie PTT is ON
  136.     bit    1,a        ; ( ie the rig is on xmit )
  137.     jr    z,td        ; If not, go try the receiver
  138.     ld    hl,(txon_)    ; If so, bump the TX on counter
  139.     inc    hl
  140.     ld    (txon_),hl
  141. td:    ld    a,(SIARR0)    ; Now check the DCD line
  142.     bit    3,a        ; to see if the RX is on
  143.     jr    z,rd        ; If not, skip over
  144.     ld    hl,(dcdon_)    ; If so, bump DCD counter
  145.     inc    hl
  146.     ld    (dcdon_),hl
  147. rd:
  148. #endasm
  149. #endif
  150. #ifdef CWID
  151. #asm
  152.     ld    A,(cwtimr_)    ; ckeck CW timer. Zero means it is not running
  153.     or    A        ; so if it tests zero, just skip over.
  154.     jr    z,timer0
  155.     dec    A        ; If it is not zero, then decrement it and
  156.     ld    (cwtimr_),A    ; store the new value. Also, if it has
  157.     call     Z,cwidbit    ; reached zero, then go get the next bit
  158. #endasm
  159. #endif
  160. #asm
  161. timer0:    ret
  162. #endasm
  163.  
  164. #endif    /* PORTABLE */
  165.  
  166. #endif    /* BANKED */
  167.  
  168. /* ***********************************************************************
  169.  * The cwid() routine is called by the timer() function
  170.  * if calibrating or cwid in progress to do the next bit 
  171.  */
  172.  
  173. #ifdef CWID
  174. #asm
  175.     .64180
  176.     extrn    cwstate_, cwbit_, cwofs_, cwdat_, cwch_, cwtimr_, cwspeed_
  177.     extrn    xFpar_, Dpar_, HRXRES, HTXSTA, SIAINI, SIAIEN, modem_type
  178.     extrn   modem_init
  179.  
  180.     global calper_,1
  181.     global caltog_,1
  182.     global caltog,1
  183.  
  184. cwidbit:
  185.     ld    HL,cwstate_    ; POINT TO STATE REGISTER
  186.     ld    A,(HL)        ; CHECK CURRENT STATE
  187.     cp    80h        ; if 80h, then we are calibrating
  188.     jp    z, calib
  189.     cp    0        ; if 0, fall thru the next jumps...
  190.     jp    M,cwbitx    ; If '-1', awaiting start of send
  191.     jr    NZ,cwbit2    ; If not zero ( 1 or 2 ) sending a delay
  192.     ld    A,(cwbit_)    ; read current char bits remaining counter
  193.     or    A        ; check if at end ( ie zero )
  194.     jr    NZ,cwbit0    ; if not, continue sending this char
  195.     ld    A,(cwofs_)    ; otherwise we need the next char, so get offs
  196.     inc    A        ; and point to the next character
  197.     ld    (cwofs_),A    ; store new offset for next time
  198.     ld    HL,cwdat_    ; now add offset to start of data table
  199.     ld    E,A
  200.     ld    D,0
  201.     add    HL,DE        ; so HL now points to next data entry
  202.     ld    A,(HL)        ; and read from it the character data,
  203.     and    1fh        ; which is in the lower 5 bits only.
  204.     ld    (cwch_),A    ; and store it in the char holding variable
  205.     ld    A,(HL)        ; get character again for the bits variable
  206.     rla            ; move the contents of the top 3 bits to
  207.     rla            ; the bottom 3 bits of the accumulator
  208.     rla            ; so that the number of bits is in
  209.     rla            ; the low 3 bits of A.
  210.     and    7        ; Now select only the 3 bits
  211.     ld    (cwbit_),A    ; store bit count
  212.     or    A        ; If zero, we are at the end of the callsign
  213.     ld    A,0        ; (just extend the delay if end of character)
  214.     jr    NZ,cwbit7    ; if not end of call, send inter char delay
  215.     ld    A,2        ; signal end of callsign by setting state to 2
  216. cwbit7:    ld    (cwstate_),A    ; and dropping thru into the delay anyway.
  217.     ld    A,(cwspeed_)    ; send a two bit delay period by reading speed
  218.     sla    A        ; doubling it and setting the tick timer
  219.     jr    cwbit3
  220.  
  221. cwbit0:    dec    A        ; continue sending this char, decrement bit
  222.     ld    (cwbit_),A    ; counter and store it
  223.     ld    A,1        ; set state to '1' for next time round
  224.     ld    (HL),A
  225.     ld    HL,cwspeed_    ; point to CWID speed bit value
  226.     ld    A,(cwch_)    ; read current character data
  227.     ld    E,A        ; store it in E temporarily
  228.     bit    0,E        ; check if LSB set. If so DASH not DOT
  229.     ld    A,(HL)        ; set speed as for a dot
  230.     jr    Z,cwbit1    ; and if it was a dash fall thru and treble it
  231.     sla    A        ; by doubling and
  232.     add    A,(HL)        ; adding the original again
  233. cwbit1:    ld    D,A        ; put delay period value in D temorarily
  234.     scf            ; set carry flag as parameter to ...
  235.     call    modem_tone    ; ... turn on the modem tone
  236.     ld    A,E        ; get current character data back again
  237.     srl    A        ; move to the next bit
  238.     ld    (cwch_),A    ; and restore the character data
  239.     ld    A,D        ; get delay period back again
  240.     jr    cwbit3
  241.  
  242. cwbit2:    scf
  243.     ccf            ; clear carry flag as parameter to modem_tone
  244.     call    modem_tone    ; to switch off the 1200 baud modem tone
  245.     dec    A        ; A contains state. If it was 1, go to cwbit4
  246.     jr    Z,cwbit4    ; otherwise fall thru to 'stop'
  247.  
  248. ; cwstop
  249.  
  250. cwstop:    ld    A,3        ; state 3 means 'i have finished'.
  251.     ld    (cwstate_),A
  252.     ld    HL,SIAINI    ; reset and initialise the channel.
  253.     ld    BC,SIACTL or ((SIAIEN-SIAINI)<<8)
  254.     otir
  255.     xor    A        ; next state of the HDLC Tx is 'idle'
  256.     ld    (HTXSTA),A
  257.     out0    (PTT),A        ; kill PTT signal
  258.     ld    A,(modem_type)    ; select the right modem type
  259.     out0    (MODEM_SEL),A
  260.     ld    A,12        ; access SCC register 12 ( brate low )
  261.     out    (SIACTL),A
  262.     ld    A,(modem_init)    ; get baud rate generator init value
  263.     out    (SIACTL),A    ; and change it back to what it was
  264.     ld    A,(SIAIW5)    ; set SIAWR5 image to initial value
  265.     ld    (SIAWR5),A
  266.     ld    A,5        ; access write register 5
  267.     out    (SIACTL),A
  268.     ld    HL,SIAWR5
  269.     res    1,(HL)        ; and kill the tone ( will be off anyway )
  270.     ld    A,(xFpar_)
  271.     or    A
  272.     jr    NZ,cwstop0
  273.     res    3,(HL)
  274. cwstop0:
  275.     ld    A,(HL)
  276.     out    (SIACTL),A
  277.     ld    A,(Dpar_)
  278.     or    A
  279.     call    Z,HRXRES
  280.     jr    cwbitx
  281.  
  282. ; delay sending routine
  283.  
  284. cwbit4:    ld    (HL),A        ; set next state from A register
  285.     ld    A,(cwspeed_)    ; read cw speed value to give single dot delay
  286. cwbit3:    ld    (cwtimr_),A    ; set the timer count to required delay
  287. cwbitx:    ret
  288.  
  289.  
  290. ; ***********************************************************************
  291. ; helper routine for cwid bits - input parameter is carry flag.
  292. ; If set, turn tone on. If clear, turn tone off. Don't change
  293. ; registers !
  294.  
  295. modem_tone:
  296.     push    AF        ; save state number whilst changing tone
  297.     ld    A,5
  298.     out    (SIACTL),A    ; register 5 gives access to the ...
  299.     ld    A,(SIAWR5)    ; ... RTS bit to switch 1200 Hz modem tone off
  300.     res    1,A        ; clear bit 1 ( oe tone off )
  301.     jr    NC, moton1    ; and if carry set, ...
  302.     set    1,A        ; then turn it on !
  303. moton1:    ld    (SIAWR5),A    ; update WR5 image
  304.     out    (SIACTL),A    ; and output to SCC
  305.     pop    AF        ; restore state
  306.     ret
  307.  
  308. ; ***********************************************************************
  309. ; This is the TNC calibrate routine
  310. ; It is called by cwid function ( above ) instead of the cwid function
  311. ;
  312.  
  313. calib:    ld    hl,calper_    ; decrement the 1 second counter
  314.     dec    (hl)        ; If it is zero, then stop sending
  315.     jr    z,cwstop    ; Otherwise, continue another second
  316.     ld    hl,caltog    ; Now decrement the toggle period counter
  317.     dec    (hl)        ; and if it is zero
  318.     jr    nz,calib0
  319.     ld    a,(caltog_)    ; then reset the counter to the start value
  320.     ld    (hl),a
  321.     ld    a,0feh        ; and toggle the o/p tone
  322.     out    (SIADAT),a
  323. calib0:    ld    a,100        ; and wake me in 10ms * 100, ie 1 second
  324.     jr    cwbit3
  325.  
  326. ; ***********************************************************************
  327. ; The cwkick() routine is called by the level 1 xmit function SIATBE()
  328. ; register definitions are as per SIBTBE internal operation !
  329. ;
  330.  
  331. ; this is the initialisation data to reprogram the SCC for cwid or calib
  332. ; after the cwid of calibrate, the main initialisation will be repeated
  333. ; which includes a channel reset.
  334. ; The code below just nobbles it to give constant tone and kills interrupts.
  335. ; In full duplex mode, we stop receiving when CWIDing etc
  336.  
  337. SIACWI:    db    4,0,5
  338. SIACW5:    db    0eah
  339.     db    3,0d9h,6,0ffh,7,0ffh,1,00h,10h
  340. SIACIX:
  341.  
  342.     public    cwkick
  343.  
  344. cwkick:    ld    A,11        ; note that HL points to state ( see SIATBE )
  345.     ld    (HL),A        ; change state
  346.     ld    HL,SIACWI    ; now initialise SCC channel A
  347.     ld    BC,SIACTL or ((SIACIX-SIACWI)<<8)
  348.     otir
  349.     ld    A,(SIACW5)    ; set WR5 image to initial value
  350.     ld    (SIAWR5),A
  351.     in    A,(SIACTL)    ; initialise the RR0 image register
  352.     ld    (SIARR0),A
  353.     ld    A,1        ; switch PTT on
  354.     out0    (PTT),A
  355.     ld    A,(cwstate_)    ; see if we are to calibrate or cwid
  356.     cp    -2        ; state of (-2) means calibrate
  357.     jr    nz, cwkik0
  358.     ld    a,(caltog_)    ; initialise toggle period to the value
  359.     ld    (caltog),a    ; set by the sysop
  360.     ld    A,80h        ; set next state to 80h ( calibrating )
  361.     jr    cwkik1
  362. cwkik0:    ld    A,1        ; select the 1200 baud modem
  363.     out0    (MODEM_SEL),A
  364.     xor    A
  365.     scf
  366.     ccf            ; for CWID, start with silence, so...
  367.     call    modem_tone    ; turn OFF the modem tone ( silence )
  368. cwkik1:    ld    (cwstate_),A    ; wait for 500 milliseconds
  369.     ld    A,50
  370.     ld    (cwtimr_),A
  371.     ret
  372.  
  373. #endasm
  374. #endif
  375.  
  376.  
  377. /**************************************************************************\
  378. *                                                                          *
  379. * "copy memory from place to place"                                        *
  380. *                                                                          *
  381. * WARNING - ANSI version handles overlapping memory. this does not         *
  382. *                                                                          *
  383. \**************************************************************************/
  384. #ifndef PORTABLE
  385. #asm
  386.     public memcpy_        ;memcpy(dest,source,count)
  387. memcpy_:
  388.     push    bc        ; save BC register as we use it
  389.     ld    hl,9        ; point to top of params ( count )
  390.     add    hl,sp
  391.     ld    b,(hl)        ; BC contains count
  392.     dec    hl
  393.     ld    c,(hl)
  394.     dec    hl
  395.     ld    d,(hl)        ; DE contains destination for now
  396.     dec    hl
  397.     ld    e,(hl)
  398.     dec    hl
  399.     ld    a,(hl)
  400.     dec    hl
  401.     ld    l,(hl)        ; HL has source address but ....
  402.     ld    h,a
  403.     ex    de,hl        ; swap DE & HL registers
  404.     ldir
  405.     pop    bc
  406.     ret
  407.  
  408. #endasm
  409. #endif
  410.  
  411. /**************************************************************************\
  412. *                                                                          *
  413. * compare - "compare memory at two locations"                              *
  414. * cmpcal  - "compare two netrom aliases                                    *
  415. * cmpid   - "compare two callsigns                                         *
  416. *                                                                          *
  417. * WARNING - assembly versions of cmpid & cmpcal jump INTO this procedure ! *
  418. *                                                                          *
  419. \**************************************************************************/
  420. #ifndef PORTABLE
  421. #asm
  422.     public compare_        ;compare(id1, id2, count )
  423. compare_:
  424.     push    bc        ; save BC register as we use it
  425.     ld    hl,9        ; point to top of params ( count )
  426.     add    hl,sp
  427.     ld    b,(hl)        ; BC contains count
  428.     dec    hl
  429.     ld    c,(hl)
  430.     dec    hl
  431.     ld    d,(hl)        ; DE contains one address
  432.     dec    hl
  433.     ld    e,(hl)
  434.     dec    hl
  435.     ld    a,(hl)
  436.     dec    hl
  437.     ld    l,(hl)        ; HL has second address
  438.     ld    h,a
  439. c0:    ld    a,(de)
  440.     cpi
  441.     jr    nz, c1
  442.     inc    de
  443.     jp    pe,c0
  444. c4:    ld    hl,1
  445.     jr    c2
  446. c1:    ld    hl,0
  447. c2:    ld    a,h
  448.     or    l
  449.     pop    bc
  450.     ret
  451.  
  452.     public cmpcal_
  453. cmpcal_:    push bc
  454.     ld    hl,7        ; point to top of params ( count )
  455.     add    hl,sp
  456.     ld    d,(hl)        ; DE contains count
  457.     dec    hl
  458.     ld    e,(hl)
  459.     dec    hl
  460.     ld    a,(hl)
  461.     dec    hl
  462.     ld    l,(hl)        ; HL has second address
  463.     ld    h,a
  464.     ld     a,(de)
  465.     cp     32
  466.     jr    z,c1
  467.     ld    a,(hl)
  468.     cp    32
  469.     jr    z,c1
  470.     ld    bc,6
  471.     jr    c0
  472.  
  473.     public cmpid_
  474. cmpid_:    push bc
  475.     ld    hl,7        ; point to top of params ( count )
  476.     add    hl,sp
  477.     ld    d,(hl)        ; DE contains count
  478.     dec    hl
  479.     ld    e,(hl)
  480.     dec    hl
  481.     ld    a,(hl)
  482.     dec    hl
  483.     ld    l,(hl)        ; HL has second address
  484.     ld    h,a
  485.     ld    bc,6
  486. c3:    ld    a,(de)
  487.     cpi
  488.     jr    nz, c1
  489.     inc    de
  490.     jp    pe,c3
  491.     ld    a,(de)
  492.     and    30
  493.     ld    b,a
  494.     ld    a,(hl)
  495.     and    30
  496.     cp    b
  497.     jr    nz,c1
  498.     jr    c4
  499.  
  500.  
  501. #endasm
  502. #endif
  503.